signature TRANSLATE =
sig
    type level
    type access			(* not the same as FRAME.access *)

    datatype exp = Ex of Tree.exp (* not the same as Absyn.exp *)
		 | Nx of Tree.stm
		 | Cx of Temp.label * Temp.label -> Tree.stm

    val outermost : level
    val newLevel : {parent : level,
		    name : Temp.label,
		    formals : bool list} -> level
    val formals : level -> access list
    val allocLocal : level -> bool -> access

    val unEx : exp -> Tree.exp
    val unNx : exp -> Tree.stm
    val unCx : exp -> (Temp.label * Temp.label) -> Tree.stm

    val procEntryExit : {level : level, body : exp} -> unit

    structure Frame : FRAME
    val getResult : unit -> Frame.frag list
	       

end

structure Translate : TRANSLATE =
struct
  structure A = Absyn
  structure E = ErrorMsg
  structure F = MipsFrame
  structure M = Temp
  structure R = Tree

  datatype level = Outermost of {frame : F.frame}
		 | FunLevel of {frame: F.frame, parent: level}

  type access = level * F.access

  fun newLevel {parent, name, formals} = ...

  val outermost = ...

  fun formals (Outermost {frame}) = ...
    | formals (level as FunLevel{frame,parent}) = ...

  fun allocLocal (level as Outermost{frame}) escape = ...
    | allocLocal (level as FunLevel{frame,parent}) escape = ...


  datatype exp = Ex of R.exp (* not the same as Absyn.exp *)
	       | Nx of R.stm
	       | Cx of M.label * M.label -> R.stm
					    
  fun unEx e = ...
  fun unNx e = ...
  fun unCx e = ...

  fun procEntryExit {level, body} = ...

  structure Frame = F
  type frag = F.frag

  fun getResult () = ...
end
